package com.sany.struts.action;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.sany.util.SapUtil;
import com.sany.web.database.DBManager;
import com.sany.web.database.SapDatabase;
import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;
import com.sap.mw.jco.JCO.Client;
import com.sap.mw.jco.JCO.Function;

public class RedetailerQueryAction extends DispatchAction implements Serializable {
	private static final long serialVersionUID = 1L;
	public ActionForward queryRedetailer(ActionMapping mapping, ActionForm forms,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		SapDatabase factory = SapUtil.getSapDatabase();
		Client conn = null;
		IRepository iRepository = factory.getConnection();
		// ��ݺ���ģ�����Ƶõ�����ģ��
		IFunctionTemplate ftemplate = iRepository
				.getFunctionTemplate("ZVRI_I_SRP_BP_READ");
		// ���캯��
		Function function = new Function(ftemplate);
		conn = JCO.getClient(DBManager.SID);
		JCO.ParameterList importParameterList  = function.getImportParameterList();
		
		importParameterList.setValue("RETAILER", "I_PARTNER");
		
		JCO.Structure   iLogon=importParameterList.getStructure("I_LOGON");
		com.sany.web.session.WebSession ws=(com.sany.web.session.WebSession) request.getSession().getAttribute("user");
		iLogon.setValue(ws.getSaleOrg(), "VKORG");
		iLogon.setValue(ws.getUserName(), "USERID");
		iLogon.setValue(ws.getBpNo(), "PARTNER");
		iLogon.setValue(ws.getLanguage(), "LANGU");
		conn.execute(function);
		
		//Get query result 
		JCO.ParameterList exportParameterList  = function.getExportParameterList();
		JCO.Structure   eBpHead=exportParameterList.getStructure("E_BP_HEAD");
		
		
		
		
		return null;
	}
}
